package com.PrayTime;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import maps.test.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.PrayTime.HijriCalendar.HijriCalendar;
import com.activity.MyMapActivity;
import com.commun.ArabicUtilities;
import com.commun.Param;

public class PrayTimeLayout extends LinearLayout {

	public PrayTimeLayout(Context context) {
		super(context);

		// this.setId(R.id.pray_time_layout);
		ArrayList<String> prayerTimes = PrayTime.getInstance()
				.GetPrayTimeStringsCustom(
						PreferenceManager.getDefaultSharedPreferences(
								MyMapActivity.getmContext()).getInt(
								"pray_time_cal_meth", 0));// Egypt

		this.setOrientation(LinearLayout.VERTICAL);
		LinearLayout.LayoutParams layoutparams = new LinearLayout.LayoutParams(
				android.view.ViewGroup.LayoutParams.FILL_PARENT,
				android.view.ViewGroup.LayoutParams.FILL_PARENT);
		this.setLayoutParams(layoutparams);
		this.setGravity(Gravity.CENTER);
		LinearLayout.LayoutParams textlayoutparams = new LinearLayout.LayoutParams(
				100, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

		// hijri title

		Date now = new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(now);

		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH)
				+ Param.CORRECTION_CALENDAR_POUR_HIJRI_MONTH;
		int day = cal.get(Calendar.DAY_OF_MONTH);

		HijriCalendar hijriCalendar = new HijriCalendar(year, month, day);

		LinearLayout.LayoutParams hijrilayoutparams = new LinearLayout.LayoutParams(
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
		LinearLayout monLinearLayout0 = new LinearLayout(context);
		monLinearLayout0.setOrientation(LinearLayout.HORIZONTAL);
		monLinearLayout0.setLayoutParams(hijrilayoutparams);
		monLinearLayout0.setGravity(Gravity.CENTER);

		TextView monTextView0 = new TextView(context);
		monTextView0.setLayoutParams(textlayoutparams);
		monTextView0.setText(hijriCalendar.getHijriYear() + "");
		monTextView0.setTextColor(Color.rgb(154, 205, 50));
		monTextView0.setGravity(Gravity.RIGHT);
		monTextView0.setTextSize(15);
		monLinearLayout0.addView(monTextView0);

		TextView monTextViewHijri = new TextView(context);
		monTextViewHijri.setLayoutParams(textlayoutparams);
		monTextViewHijri = ArabicUtilities.getArabicEnabledTextView(context,
				monTextViewHijri);
		monTextViewHijri.setText(hijriCalendar.getHijriMonthArabe().get(
				hijriCalendar.getHijriMonthName()));

		monTextViewHijri.setTextColor(Color.rgb(154, 205, 50));
		monTextViewHijri.setTextSize(15);
		monTextViewHijri.setGravity(Gravity.CENTER_HORIZONTAL);
		monLinearLayout0.addView(monTextViewHijri);

		TextView monTextView00 = new TextView(context);
		monTextView00.setLayoutParams(textlayoutparams);
		monTextView00.setText(hijriCalendar.getHijriDay() + "");
		monTextView00.setTextColor(Color.rgb(154, 205, 50));
		monLinearLayout0.addView(monTextView00);
		monTextView00.setTextSize(15);

		this.addView(monLinearLayout0);

		// fake layout
		int theEmptySpace = 20;
		LinearLayout.LayoutParams fakelayoutparams = new LinearLayout.LayoutParams(
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT, theEmptySpace);
		LinearLayout monLinearLayoutFake = new LinearLayout(context);
		monLinearLayoutFake.setOrientation(LinearLayout.HORIZONTAL);
		monLinearLayoutFake.setLayoutParams(fakelayoutparams);
		monLinearLayoutFake.setGravity(Gravity.CENTER);
		this.addView(monLinearLayoutFake);

		// FAJR

		LinearLayout monLinearLayout1 = new LinearLayout(context);
		monLinearLayout1.setOrientation(LinearLayout.HORIZONTAL);
		layoutparams = new LinearLayout.LayoutParams(
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
		monLinearLayout1.setLayoutParams(layoutparams);
		monLinearLayout1.setGravity(Gravity.CENTER);

		TextView monTextView1 = new TextView(context);
		monTextView1.setLayoutParams(textlayoutparams);
		monTextView1.setText("Fajr");
		monTextView1.setTextColor(Color.WHITE);
		monLinearLayout1.addView(monTextView1);

		TextView monTextView2 = new TextView(context);
		monTextView2.setLayoutParams(textlayoutparams);
		monTextView2.setText(prayerTimes.get(0));
		monTextView2.setTextColor(Color.WHITE);
		monLinearLayout1.addView(monTextView2);

		ImageView imageView1 = new ImageView(context);
		imageView1.setLayoutParams(layoutparams);
		imageView1.setImageResource(R.drawable.salat_icon_fajr);
		monLinearLayout1.addView(imageView1);
		this.addView(monLinearLayout1);

		//
		LinearLayout monLinearLayout2 = new LinearLayout(context);
		monLinearLayout2.setOrientation(LinearLayout.HORIZONTAL);
		layoutparams = new LinearLayout.LayoutParams(
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
		monLinearLayout2.setLayoutParams(layoutparams);
		monLinearLayout2.setGravity(Gravity.CENTER);

		TextView monTextView3 = new TextView(context);
		monTextView3.setLayoutParams(textlayoutparams);
		monTextView3.setText("Shourouq");
		monTextView3.setTextColor(Color.WHITE);
		monLinearLayout2.addView(monTextView3);

		TextView monTextView4 = new TextView(context);
		monTextView4.setLayoutParams(textlayoutparams);
		monTextView4.setText(prayerTimes.get(1));
		monTextView4.setTextColor(Color.WHITE);
		monLinearLayout2.addView(monTextView4);

		ImageView imageView2 = new ImageView(context);
		imageView2.setLayoutParams(layoutparams);
		imageView2.setImageResource(R.drawable.salat_icon_shourouk);
		monLinearLayout2.addView(imageView2);
		this.addView(monLinearLayout2);
		//

		LinearLayout monLinearLayout3 = new LinearLayout(context);
		monLinearLayout3.setOrientation(LinearLayout.HORIZONTAL);
		monLinearLayout3.setLayoutParams(layoutparams);
		monLinearLayout3.setGravity(Gravity.CENTER);

		TextView monTextView5 = new TextView(context);
		monTextView5.setLayoutParams(textlayoutparams);
		monTextView5.setText("Dhohr");
		monTextView5.setTextColor(Color.WHITE);
		monLinearLayout3.addView(monTextView5);

		TextView monTextView6 = new TextView(context);
		monTextView6.setLayoutParams(textlayoutparams);
		monTextView6.setText(prayerTimes.get(2));
		monTextView6.setTextColor(Color.WHITE);
		monLinearLayout3.addView(monTextView6);

		ImageView imageView3 = new ImageView(context);
		imageView3.setLayoutParams(layoutparams);
		imageView3.setImageResource(R.drawable.salat_icon_dhohr);
		monLinearLayout3.addView(imageView3);
		this.addView(monLinearLayout3);

		//

		LinearLayout monLinearLayout4 = new LinearLayout(context);
		monLinearLayout4.setOrientation(LinearLayout.HORIZONTAL);
		monLinearLayout4.setLayoutParams(layoutparams);
		monLinearLayout4.setGravity(Gravity.CENTER);

		TextView monTextView7 = new TextView(context);
		monTextView7.setLayoutParams(textlayoutparams);
		monTextView7.setText("Asr");
		monTextView7.setTextColor(Color.WHITE);
		monLinearLayout4.addView(monTextView7);

		TextView monTextView8 = new TextView(context);
		monTextView8.setLayoutParams(textlayoutparams);
		monTextView8.setText(prayerTimes.get(3));
		monTextView8.setTextColor(Color.WHITE);
		monLinearLayout4.addView(monTextView8);

		ImageView imageView4 = new ImageView(context);
		imageView4.setLayoutParams(layoutparams);
		imageView4.setImageResource(R.drawable.salat_icon_asr);
		monLinearLayout4.addView(imageView4);

		this.addView(monLinearLayout4);

		// 
		LinearLayout monLinearLayout5 = new LinearLayout(context);
		monLinearLayout5.setOrientation(LinearLayout.HORIZONTAL);
		monLinearLayout5.setLayoutParams(layoutparams);
		monLinearLayout5.setGravity(Gravity.CENTER);

		TextView monTextView9 = new TextView(context);
		monTextView9.setLayoutParams(textlayoutparams);
		monTextView9.setText("Maghrib");
		monTextView9.setTextColor(Color.WHITE);
		monLinearLayout5.addView(monTextView9);

		TextView monTextView10 = new TextView(context);
		monTextView10.setLayoutParams(textlayoutparams);
		monTextView10.setText(prayerTimes.get(4));
		monTextView10.setTextColor(Color.WHITE);
		monLinearLayout5.addView(monTextView10);

		ImageView imageView5 = new ImageView(context);
		imageView5.setLayoutParams(layoutparams);
		imageView5.setImageResource(R.drawable.salat_icon_maghreb);
		monLinearLayout5.addView(imageView5);

		this.addView(monLinearLayout5);

		// ISHA
		LinearLayout monLinearLayout6 = new LinearLayout(context);
		monLinearLayout6.setOrientation(LinearLayout.HORIZONTAL);
		monLinearLayout6.setLayoutParams(layoutparams);
		monLinearLayout6.setGravity(Gravity.CENTER);

		TextView monTextView11 = new TextView(context);
		monTextView11.setLayoutParams(textlayoutparams);
		monTextView11.setText("Isha");
		monTextView11.setTextColor(Color.WHITE);
		monLinearLayout6.addView(monTextView11);

		TextView monTextView12 = new TextView(context);
		monTextView12.setLayoutParams(textlayoutparams);
		monTextView12.setText(prayerTimes.get(6));
		monTextView12.setTextColor(Color.WHITE);
		monLinearLayout6.addView(monTextView12);

		ImageView imageView6 = new ImageView(context);
		imageView5.setLayoutParams(layoutparams);
		imageView6.setImageResource(R.drawable.salat_icon_isha);
		monLinearLayout6.addView(imageView6);

		this.addView(monLinearLayout6);

	}

	public static void Renitialisation(Context context, int meth_cal) {

		RelativeLayout ongletSalatTimeLinearLayout = (RelativeLayout) ((Activity) context)
				.findViewById(R.id.OngletSalatTime);
		LinearLayout layout = (LinearLayout) ongletSalatTimeLinearLayout
				.getChildAt(1);

		layout.setVisibility(View.INVISIBLE);
		ongletSalatTimeLinearLayout.removeViewAt(1);

		ongletSalatTimeLinearLayout.addView(new PrayTimeLayout(context));

	}

}